package com.mt.channel.service.impl;

import java.util.List;
import java.util.Map;


import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.mt.channel.api.service.IChannelAccountService;
import com.mt.channel.entity.ChannelAccountEntity;
import com.mt.channel.entity.ChannelApplyDropCourseEntity;
import com.mt.channel.entity.ChannelOrderEntity;
import com.mt.channel.service.model.ChannelAccountServiceModel;
import com.mt.common.PagerInfo;
import com.mt.common.ServiceResult;
import com.mt.common.constants.BaseErrorConstants;
import org.springframework.stereotype.Service;

@Service
public class ChannelAccountServiceImpl implements IChannelAccountService {

    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ChannelAccountServiceImpl.class);

    @Autowired
    private ChannelAccountServiceModel channelAccountServiceModel;

    public ServiceResult<ChannelAccountEntity> findInfo(Map<String, Object> params) {
        // 查询用户信息
        ServiceResult<ChannelAccountEntity> result = null;
        // 该参数标识前段是否需要权限数据
        try {
            result = channelAccountServiceModel.selectInfo(params);
        } catch (Exception e) {
            LOGGER.error("[ChannelAccountServiceImpl][findInfo]：query findInfo occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "查询详情错误");
        }
        return result;
    }

    public ServiceResult<List<ChannelAccountEntity>> findList(Map<String, Object> params, PagerInfo<?> pagerInfo) {
        ServiceResult<List<ChannelAccountEntity>> result = new ServiceResult<List<ChannelAccountEntity>>();
        try {
            result = channelAccountServiceModel.selectList(params, pagerInfo);
        } catch (Exception e) {
            LOGGER.error("[ChannelAccountServiceImpl][findList]：query findList occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "查询列表错误");
        }

        return result;
    }

    public ServiceResult<Integer> doInsert(ChannelAccountEntity channelAccountEntity) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = channelAccountServiceModel.insert(channelAccountEntity);
        } catch (Exception e) {
            LOGGER.error("[ChannelAccountServiceImpl][doInsert]：query doInsert occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "创建信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> doUpdateRelate(ChannelAccountEntity channelAccountEntity) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = channelAccountServiceModel.updateRelate(channelAccountEntity);
        } catch (Exception e) {
            LOGGER.error("[ChannelAccountServiceImpl][doUpdate]：query doUpdate occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "编辑信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> doDeleteById(Integer channelAccountId) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = channelAccountServiceModel.deleteByPrimaryKey(channelAccountId);
        } catch (Exception e) {
            LOGGER.error("[ChannelAccountServiceImpl][doDeleteById]：query doDeleteById occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "删除信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> doUpdate(ChannelAccountEntity channelAccountEntity) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = channelAccountServiceModel.updateByPrimaryKeySelective(channelAccountEntity);
        } catch (Exception e) {
            LOGGER.error("[ChannelAccountServiceImpl][doUpdate]：query doUpdate occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "更新信息错误.");
        }
        return result;
    }

    public ServiceResult<Integer> channelApplyDropCourseUpdateRelate(ChannelAccountEntity channelAccountEntity,
        ChannelOrderEntity channelOrderEntity, ChannelApplyDropCourseEntity channelApplyDropCourseEntity) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = channelAccountServiceModel.channelApplyDropCourseUpdateRelate(channelAccountEntity,channelOrderEntity,channelApplyDropCourseEntity);
        } catch (Exception e) {
            LOGGER.error("[ChannelAccountServiceImpl][doUpdate]：query doUpdate occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "编辑信息错误");
        }
        return result;
    }

}
